package com.javachmapi.springbootsms.qiniuconfig;

import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.sms.SmsManager;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 写法二、通过@Value读取配置文件的属性
 * 记得加上@Component变成容器，并且注入此容器
 * @author 宋利军
 */
@Component
public class QiniuTowConfig {

    @Value("${qiniu.accessKey}")
    private String accessKey;

    @Value("${qiniu.secretKey}")
    private String secretKey;

    public void sendSmsManager(String templateId,String[] iphones,Map map){
        Auth auth = Auth.create(accessKey,secretKey);
        // 实例化一个SmsManager对象
        SmsManager smsManager = new SmsManager(auth);
        try {
            Response resp = smsManager.sendMessage(templateId,iphones, map);
        } catch (QiniuException e) {
            System.out.println(e);
        }
    }
}
